<?php

class ThreadsAction extends CommonAction{
	public function index() {
		$link=mysql_connect("w.mysql.internal.strends.com.cn","design","IT3I4XWs") or die("数据库连接失败：".mysql_error());
		
		mysql_select_db("discuz");
		
		mysql_set_charset("utf8");
		
		$name=$this->getActionName();
		
	
		$num=20;
		$start=$page*$num-$num;
		$end=$page*$num;
		$sql="select count(*) as num from cdb_threads where fid in(3)";
		$result=mysql_query($sql);
		$rows=mysql_fetch_assoc($result);
		
		$count=$rows['num'];
		import("ORG.Util.Page"); 
		
		$Page       = new Page($count,14); 
		$show       = $Page->show(); 
		
		//$sql="select *  from cdb_threads where fid in(3) and displayorder >=0 limit $Page->firstRow,$Page->listRows";
		$sql="SELECT t.tid,t.fid,t.readperm,t.author,t.authorid,t.subject,t.dateline,t.lastpost,t.lastposter,t.views,t.replies,t.highlight,t.digest,t.typeid,t.sortid ,a.remote,a.attachment,a.thumb FROM `cdb_threads` t INNER JOIN `cdb_attachments` a ON a.tid=t.tid WHERE t.readperm='0' AND t.fid IN ('3') AND a.isimage IN ('1', '-1') AND a.readperm='0' AND a.price='0'  AND t.displayorder>='0' AND t.fid>'0' GROUP BY a.tid ORDER BY t.views DESC LIMIT $Page->firstRow,$Page->listRows";
		$res=mysql_query($sql);
		
		while($row=mysql_fetch_assoc($res)){
			$voList[]=$row;
		}
		
		$url="";
		foreach($voList as $key=>&$val){
			$val['dateline']=date('Y-n-j H:s',$val['dateline']);
			$val['lastpost']=date('Y-n-j H:s',$val['lastpost']);
			$val['attachment']="http://www.stylehouse.com.cn/design/attachments/".$val['attachment'];
		}
		
		$this->assign ( 'list', $voList);
		$this->assign ( 'page', $show);
		if ($count > 0) {
			Cookie::set ('_currentUrl_',$p->currentUrl);
			Cookie::set ($returnUrl,$p->currentUrl);
		}else{
			Cookie::set ( '_currentUrl_', U($this->getActionName() . "/index"));
			Cookie::set ($returnUrl, U($this->getActionName() . "/index"));
		}
	
		$this->display ();
		return;
	}
	
	
	public function  recommend(){
		if($_GET['type']=="yes"){
			$tui=1;
		}else{
			$tui=0;
		}
		$id=$_GET['id'];
		$link=mysql_connect("w.mysql.internal.strends.com.cn","design","IT3I4XWs") or die("数据库连接失败：".mysql_error());
		
		mysql_select_db("discuz");
		
		mysql_set_charset("utf8");
		if($tui){
			$sql="update set recommend = 1 from cdb_threads where tid={$id}";
		}else{
			$sql="update set recommend = 0 from cdb_threads where tid={$id}";
		}
		$res=mysql_query($sql);
		$num=mysql_affected_rows();
		if($num){
			echo "ok";
		}else{
			echo "fail";
		}
		
	}
	
	
}